import contextlib
import wave
import os

test_path = '/home/asr_deploy_test/asr_test_file/'

def get_mean_length():
    file_dict = {}
    length = []
    for dir in os.listdir(test_path):
        files_path = os.path.join(test_path, dir)
        for file in os.listdir(files_path):
            path = os.path.join(files_path, file)
            file_dict[file] = path
            with contextlib.closing(wave.open(path, 'r')) as f:
                frames = f.getnframes()
                rate = f.getframerate()
                wav_length = frames / float(rate)
                length.append(wav_length)
    print(np.mean(length))


if __name__ == '__main__':
    # one_list_test()
    # evaluation()
    get_mean_length()
